/**
 * 
 */
package top.ewind.interceptor.mqtt;

import java.nio.ByteBuffer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jfinal.plugin.redis.Redis;

import top.ewind.controller.common.RedisConstants;
import top.ewind.util.DateUtil;

/**
 * @author wangchao
 *
 */
public class UserStrategy extends AbstractMsgStrategy implements IMsgStrategy {
	private final static Logger log = LoggerFactory.getLogger(DeviceStrategy.class);
	/* (non-Javadoc)
	 * @see top.ewind.interceptor.mqtt.IMsgStrategy#onConnect(java.lang.String)
	 */
	@Override
	public void onConnect(String id) {
		//更新用户状态
	/*	DeviceUser deviceUser = DeviceUser.dao.findById(id);
		if(deviceUser!=null){
			deviceUser.set("stat", 2).update();
		}*/
	}

	/* (non-Javadoc)
	 * @see top.ewind.interceptor.mqtt.IMsgStrategy#onDisconnect(java.lang.String)
	 */
	@Override
	public void onDisconnect(String id) {
		//更新用户状态
		/*DeviceUser deviceUser = DeviceUser.dao.findById(id);
		if(deviceUser!=null&&deviceUser.getStat()==2){
			deviceUser.set("stat", 1).update();
		}*/

	}

	/* (non-Javadoc)
	 * @see top.ewind.interceptor.mqtt.IMsgStrategy#onPublish(java.lang.String, java.nio.ByteBuffer)
	 */
	@Override
	public void onPublish(String pid,String id, ByteBuffer buff) {
		//log.error("用户消息："+decodeToStr(buff));
		Redis.use().hincrBy(RedisConstants.USER_OPR_DAY+id, DateUtil.todayStr(), 1);
		Redis.use().hincrBy(RedisConstants.USER_OPR_MONTH+id, DateUtil.monthStr(), 1);
	}

}
